﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessLogicLayer;
using BusinessEntities;
using System.Text.RegularExpressions;

namespace QL_HoSoBA
{
    public partial class frmYTa : Form
    {
        public frmYTa()
        {
            InitializeComponent();
        }
        public static string taikhoan = "", matkhau = "", chucvu = "", manv = "", tennv = "", phongkham = "";
        private static HoSoBA_Manager hoso = new HoSoBA_Manager();
        private static PhieuDieuTri_Manager phieudt = new PhieuDieuTri_Manager();
        private static PhieuTheoDoi_Manager phieutd = new PhieuTheoDoi_Manager();
        private void frmYTa_Load(object sender, EventArgs e)
        {
            //taikhoan = frmMain.taikhoan;
            //matkhau = frmMain.matkhau;
            //chucvu = frmMain.chucvu;
            //manv = frmMain.manv;
            //tennv = frmMain.tennv;
            //phongkham = frmMain.phongkham;
            taikhoan = frmHeThong.taikhoan;
            matkhau = frmHeThong.matkhau;
            chucvu = frmHeThong.chucvu;
            manv = frmHeThong.manv;
            tennv = frmHeThong.tennv;
            phongkham = frmHeThong.phongkham;
            grwDSBN.DataSource = hoso.HoSoBA_DSBA_PhongBenh(phongkham);
            grwDSBN.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Regular,
                System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            grwDSBN.Columns[0].Width = 80;
            grwDSBN.Columns[1].Width = 120;
            grwDSBN.Columns[2].Width = 120;

            grwDSBN1.DataSource = hoso.HoSoBA_DSBA_PhongBenh(phongkham);
            grwDSBN1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Regular,
                System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            grwDSBN1.Columns[0].Width = 80;
            grwDSBN1.Columns[1].Width = 120;
            grwDSBN1.Columns[2].Width = 120;

            this.Text = this.Text + " " + DateTime.Now.ToShortDateString();
            lblName1.Text += " " + phongkham.ToUpper() + " NGÀY: " + DateTime.Now.ToShortDateString().ToUpper();
        }

        #region Show TabControls theo chỉ mục
        public void ShowForm(int index)
        {
            tabControlPTD.SelectTab(index);
            tabControlPTD.Show();
        }
        #endregion

        private void grwDSBN_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int row = e.RowIndex;
                string MaBA = grwDSBN.Rows[row].Cells[0].Value.ToString();
                DataTable tb = hoso.HoSoBA_Kham_TimTheoMaBA1(int.Parse(MaBA));
                if (tb.Rows.Count > 0)
                {
                    txtMaBA.Text = tb.Rows[0][0].ToString();
                    dtpNgayNhapVien.Value = DateTime.Parse(tb.Rows[0][2].ToString());
                    txtHoTen.Text = tb.Rows[0][4].ToString();
                    dtpNgaySinh.Value = DateTime.Parse(tb.Rows[0][5].ToString());
                    txtGioiTinh.Text = tb.Rows[0][7].ToString();
                    txtChuanDoan.Text = tb.Rows[0][14].ToString();
                    txtGiuong.Text = tb.Rows[0][20].ToString();
                    txtMaBS.Text = tb.Rows[0][23].ToString();
                    txtTenBS.Text = tb.Rows[0][24].ToString();
                    try
                    {
                        DataTable tb1 = phieudt.PhieuDieuTri_MaBA_TrongNgay(int.Parse(txtMaBA.Text));
                        if (tb1.Rows.Count > 0)
                        {
                            dtpNgayGhi.Value = DateTime.Parse(tb1.Rows[0][2].ToString());
                            txtYLenh.Text = tb1.Rows[0][3].ToString();
                        }
                        else
                        {
                            dtpNgayGhi.Value = DateTime.Now;
                            txtYLenh.Text = "";
                        }
                    }
                    catch { }
                }
            }
            catch { }
        }

        private void grwDSBN1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int row = e.RowIndex;
                string MaBA = grwDSBN1.Rows[row].Cells[0].Value.ToString();
                DataTable tb = hoso.HoSoBA_Kham_TimTheoMaBA1(int.Parse(MaBA));
                if (tb.Rows.Count > 0)
                {
                    txtMaBA1.Text = tb.Rows[0][0].ToString();
                    dtpNgayNhapVien1.Value = DateTime.Parse(tb.Rows[0][2].ToString());
                    txtHoTen1.Text = tb.Rows[0][4].ToString();
                    dtpNgaySinh1.Value = DateTime.Parse(tb.Rows[0][5].ToString());
                    txtGioiTinh1.Text = tb.Rows[0][7].ToString();
                    txtGiuong1.Text = tb.Rows[0][20].ToString();
                    btnGhi1.Enabled = true;
                    btnCapNhat.Enabled = false;
                }
            }
            catch { }
        }
        private string GomKhoangTrang(string str)
        {
            string strPattern = @"[\s]+";
            Regex rgx = new Regex(strPattern);
            string Ouput = rgx.Replace(str, " ");
            return Ouput.Trim();
        }
        private void btnGhi1_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDienBien1.Text.Trim() != "")
                {
                    if (MessageBox.Show("Bạn có muốn thêm không ?", "???", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int kq = phieutd.PhieuTheoDoi_Them(new PhieuTheoDoi_Info(txtMaPhieu1.Text, int.Parse(txtMaBA1.Text), dtpNgayGhi1.Value,
                            GomKhoangTrang(txtDienBien1.Text).Trim(), manv, tennv));
                        if (kq == 1)
                        {
                            MessageBox.Show("Thêm thành công !", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            button4.PerformClick();
                            btnNhapMoi1.PerformClick();
                            errorProvider1.Clear();
                            return;
                        }
                        else
                            MessageBox.Show("Thêm thất bại !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                        return;
                }
                else
                    MessageBox.Show("Dữ liệu nhập không hợp lệ !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch { }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            grwPhieuTD.DataSource = phieutd.PhieuTheoDoi_All_TrongNgay(manv);
            grwPhieuTD.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Regular,
                System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            grwPhieuTD.Columns[0].Width = 110;
            grwPhieuTD.Columns[1].Width = 110;
            grwPhieuTD.Columns[2].Width = 150;
            grwPhieuTD.Columns[3].Width = 600;
        }

        private void txtMaPhieu1_TextChanged(object sender, EventArgs e)
        {
            if (txtMaPhieu1.Text.Trim() != "")
                btnCapNhat.Enabled = true;
            else
                btnCapNhat.Enabled = false;
        }

        private void grwPhieuTD_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int row = e.RowIndex;
                txtMaPhieu1.Text = grwPhieuTD.Rows[row].Cells[0].Value.ToString();
                txtMaBA1.Text = grwPhieuTD.Rows[row].Cells[1].Value.ToString();
                dtpNgayGhi1.Value = DateTime.Parse(grwPhieuTD.Rows[row].Cells[2].Value.ToString());
                txtDienBien1.Text = grwPhieuTD.Rows[row].Cells[3].Value.ToString();
                btnGhi1.Enabled = false;
                btnCapNhat.Enabled = true;
                try
                {
                    DataTable tb = hoso.HoSoBA_Kham_TimTheoMaBA1(int.Parse(txtMaBA1.Text));
                    if (tb.Rows.Count > 0)
                    {
                        dtpNgayNhapVien1.Value = DateTime.Parse(tb.Rows[0][2].ToString());
                        txtHoTen1.Text = tb.Rows[0][4].ToString();
                        dtpNgaySinh1.Value = DateTime.Parse(tb.Rows[0][5].ToString());
                        txtGioiTinh1.Text = tb.Rows[0][7].ToString();
                        txtGiuong1.Text = tb.Rows[0][20].ToString();
                        btnGhi1.Enabled = false;
                        btnCapNhat.Enabled = true;
                    }
                }
                catch { }
            }
            catch { }
        }

        private void txtMaBA1_TextChanged(object sender, EventArgs e)
        {
            if (txtMaBA1.Text == "")
                btnGhi1.Enabled = false;
            else
                btnGhi1.Enabled = true;
        }

        private void btnThoat1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát không ?", "???", MessageBoxButtons.YesNo,
                MessageBoxIcon.Question) == DialogResult.Yes)
                this.Close();
        }

        private void btnNhapMoi1_Click(object sender, EventArgs e)
        {
            dtpNgayGhi1.Value = DateTime.Now;
            txtDienBien1.Text = "";
            txtMaPhieu1.Text = "";
            txtMaBA1.Text = "";
            dtpNgayNhapVien1.Value = DateTime.Now;
            txtHoTen1.Text = "";
            dtpNgaySinh1.Value = DateTime.Now;
            txtGioiTinh1.Text = "";
            txtGiuong1.Text = "";
            btnGhi1.Enabled = false;
            btnCapNhat.Enabled = false;
            grwPhieuTD.DataSource = new object();
        }
        private void chkMaPhieu4_CheckedChanged(object sender, EventArgs e)
        {
            if (chkMaPhieu4.Checked)
            {
                AnChon1();
                NhapMoi1();
                chkMaPhieu4.Enabled = true;
                txtMaPhieu4.Enabled = true;
                btnTimKiem4.Enabled = true;
            }
            else
            {
                HienChon1();
                AnNhap1();
                NhapMoi1();
                btnTimKiem4.Enabled = false;
            }
        }

        private void chkMaBA4_CheckedChanged(object sender, EventArgs e)
        {
            if (chkMaBA4.Checked)
            {
                AnChon1();
                NhapMoi1();
                chkMaBA4.Enabled = true;
                txtMaBA4.Enabled = true;
                btnTimKiem4.Enabled = true;
            }
            else
            {
                HienChon1();
                AnNhap1();
                NhapMoi1();
                btnTimKiem4.Enabled = false;
            }
        }

        private void chkNgayGhi4_CheckedChanged(object sender, EventArgs e)
        {
            if (chkNgayGhi4.Checked)
            {
                AnChon1();
                NhapMoi1();
                chkNgayGhi4.Enabled = true;
                dtpNgayGhi4.Enabled = true;
                dtpNgayGhi4.MaxDate = DateTime.Now;
                btnTimKiem4.Enabled = true;
            }
            else
            {
                HienChon1();
                AnNhap1();
                NhapMoi1();
                btnTimKiem4.Enabled = false;
            }
        }

        private void chkThangGhi4_CheckedChanged(object sender, EventArgs e)
        {
            if (chkThangGhi4.Checked)
            {
                AnChon1();
                NhapMoi1();
                chkThangGhi4.Enabled = true;
                dtpThangGhi.Enabled = true;
                dtpThangGhi.MaxDate = DateTime.Now;
                btnTimKiem4.Enabled = true;
            }
            else
            {
                HienChon1();
                AnNhap1();
                NhapMoi1();
                btnTimKiem4.Enabled = false;
            }
        }

        private void chkNamGhi4_CheckedChanged(object sender, EventArgs e)
        {
            if (chkNamGhi4.Checked)
            {
                AnChon1();
                NhapMoi1();
                chkNamGhi4.Enabled = true;
                dtpNamGhi.Enabled = true;
                dtpNamGhi.MaxDate = DateTime.Now;
                btnTimKiem4.Enabled = true;
            }
            else
            {
                HienChon1();
                AnNhap1();
                NhapMoi1();
                btnTimKiem4.Enabled = false;
            }
        }

        private void chkDaXuatVien4_CheckedChanged(object sender, EventArgs e)
        {
            if (chkDaXuatVien4.Checked)
            {
                AnChon1();
                NhapMoi1();
                btnTimKiem4.Enabled = true;
            }
            else
            {
                HienChon1();
                AnNhap1();
                NhapMoi1();
                btnTimKiem4.Enabled = false;
            }
        }

        private void AnChon1()
        {
            chkMaBA4.Enabled = false;
            chkMaPhieu4.Enabled = false;
            chkNgayGhi4.Enabled = false;
            chkThangGhi4.Enabled = false;
            chkNamGhi4.Enabled = false;
        }

        private void HienChon1()
        {
            chkMaBA4.Enabled = true;
            chkMaPhieu4.Enabled = true;
            chkNgayGhi4.Enabled = true;
            chkThangGhi4.Enabled = true;
            chkNamGhi4.Enabled = true;
        }

        private void AnNhap1()
        {
            txtMaPhieu4.Enabled = false;
            txtMaBA4.Enabled = false;
            dtpNgayGhi4.Enabled = false;
            dtpThangGhi.Enabled = false;
            dtpNamGhi.Enabled = false;
            dtpThangGhi.Value = DateTime.Now.Date;
            dtpNamGhi.Value = DateTime.Now.Date;
            dtpNgayGhi4.Value = DateTime.Now.Date;
        }

        private void NhapMoi1()
        {
            txtMaPhieu4.Text = "";
            txtMaBA4.Text = "";
            dtpThangGhi.Value = DateTime.Now.Date;
            dtpNamGhi.Value = DateTime.Now.Date;
            dtpNgayGhi4.Value = DateTime.Now.Date;
            grwPTD2.DataSource = new object();
            txtTongSo3.Clear();
        }

        private int chon1;
        private int LayChon1()
        {
            if (chkMaPhieu4.Checked)
                chon1 = 0;
            if (chkMaBA4.Checked)
                chon1 = 1;
            if (chkNgayGhi4.Checked)
                chon1 = 2;
            if (chkThangGhi4.Checked)
                chon1 = 3;
            if (chkNamGhi4.Checked)
                chon1 = 4;
            if (chkDaXuatVien4.Checked)
                chon1 = 5;
            return chon1;
        }

        private void btnTimKiem4_Click(object sender, EventArgs e)
        {
            LayChon1();
            switch (chon1)
            {
                case 0:
                    if (txtMaPhieu4.Text.Trim() != "")
                    {
                        DataTable dt = phieutd.PhieuTheoDoi_TimTheoMaPhieu_MaYTa(manv, int.Parse(txtMaPhieu4.Text));
                        if (dt.Rows.Count != 0)
                        {
                            grwPTD2.DataSource = dt;
                            CanChinh3(grwPTD2);
                            txtTongSo3.Text = grwPTD2.RowCount.ToString();
                            btnXoa4.Enabled = true;
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Mã phiếu [" + txtMaPhieu4.Text + "] không tồn tại !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            grwPTD2.DataSource = new object();
                            txtTongSo3.Clear();
                            btnXoa4.Enabled = false;
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Bạn chưa nhập mã phiếu !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        grwPTD2.DataSource = new object();
                        txtTongSo3.Clear();
                        btnXoa4.Enabled = false;
                    }
                    break;

                case 1:
                    if (txtMaBA4.Text.Trim() != "")
                    {
                        DataTable dt = phieutd.PhieuTheoDoi_TimTheoMaBA_MaYTa(manv, int.Parse(txtMaBA4.Text));
                        if (dt.Rows.Count != 0)
                        {
                            grwPTD2.DataSource = dt;
                            CanChinh3(grwPTD2);
                            txtTongSo3.Text = grwPTD2.RowCount.ToString();
                            btnXoa4.Enabled = true;
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Mã bệnh án [" + txtMaBA4.Text + "] không có phiếu theo dõi !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            grwPTD2.DataSource = new object();
                            txtTongSo3.Clear();
                            btnXoa4.Enabled = false;
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Bạn chưa nhập mã bệnh án !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        grwPTD2.DataSource = new object();
                        txtTongSo3.Clear();
                        btnXoa4.Enabled = false;
                    }
                    break;

                case 2:
                    DataTable dt1 = phieutd.PhieuTheoDoi_TimTheoNgayGhi_MaYTa(manv, dtpNgayGhi4.Value);
                    if (dt1.Rows.Count != 0)
                    {
                        grwPTD2.DataSource = dt1;
                        CanChinh3(grwPTD2);
                        txtTongSo3.Text = grwPTD2.RowCount.ToString();
                        btnXoa4.Enabled = true;
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Ngày [" + dtpNgayGhi4.Value.ToShortDateString() + "] không có phiếu theo dõi lưu trữ !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        grwPTD2.DataSource = new object();
                        txtTongSo3.Clear();
                        btnXoa4.Enabled = false;
                    }
                    break;

                case 3:
                    DataTable dt2 = phieutd.PhieuTheoDoi_TimTheoThangGhi_MaYTa(manv, dtpThangGhi.Value);
                    if (dt2.Rows.Count != 0)
                    {
                        grwPTD2.DataSource = dt2;
                        CanChinh3(grwPTD2);
                        txtTongSo3.Text = grwPTD2.RowCount.ToString();
                        btnXoa4.Enabled = true;
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Tháng [" + dtpThangGhi.Value.Month.ToString() + "/" + dtpThangGhi.Value.Year.ToString() + "] không có phiếu theo dõi lưu trữ !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        grwPTD2.DataSource = new object();
                        txtTongSo3.Clear();
                        btnXoa4.Enabled = false;
                    }
                    break;
                case 4:
                    DataTable dt3 = phieutd.PhieuTheoDoi_TimTheoNamGhi_MaYTa(manv, dtpNamGhi.Value);
                    if (dt3.Rows.Count != 0)
                    {
                        grwPTD2.DataSource = dt3;
                        CanChinh3(grwPTD2);
                        txtTongSo3.Text = grwPTD2.RowCount.ToString();
                        btnXoa4.Enabled = true;
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Năm [" + dtpNamGhi.Value.Year.ToString() + "] không có phiếu theo dõi lưu trữ !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        grwPTD2.DataSource = new object();
                        txtTongSo3.Clear();
                        btnXoa4.Enabled = false;
                    }
                    break;
                case 5:
                    try
                    {
                        DataTable dt4 = phieutd.PhieuTheoDoi_BNXuatVien_MaYTa(manv);
                        if (dt4.Rows.Count != 0)
                        {
                            grwPTD2.DataSource = dt4;
                            CanChinh3(grwPTD2);
                            txtTongSo3.Text = grwPTD2.RowCount.ToString();
                            btnXoa4.Enabled = true;
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Không có phiếu theo dõi của bệnh nhân đã xuất viện !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            grwPTD2.DataSource = new object();
                            txtTongSo3.Clear();
                            btnXoa4.Enabled = false;
                        }
                    }
                    catch
                    { }
                    break;
            }
        }
        private void CanChinh3(DataGridView grw)
        {
            try
            {
                grw.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Regular,
                    System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                grw.Columns[0].Width = 100;
                grw.Columns[1].Width = 100;
                grw.Columns[2].Width = 150;
                grw.Columns[3].Width = 750;
            }
            catch { }
        }
        private void btnNhapMoi4_Click(object sender, EventArgs e)
        {
            AnChon1();
            AnNhap1();
            HienChon1();
            btnXoa4.Enabled = false;
            btnTimKiem4.Enabled = false;
            grwPTD2.DataSource = new object();
            txtTongSo3.Clear();
            chkMaBA4.Checked = false;
            chkMaPhieu4.Checked = false;
            chkNgayGhi4.Checked = false;
            chkThangGhi4.Checked = false;
            chkNamGhi4.Checked = false;
        }

        private void chkNamGhi4_CheckedChanged_1(object sender, EventArgs e)
        {
            if (chkNamGhi4.Checked)
            {
                AnChon1();
                NhapMoi1();
                chkNamGhi4.Enabled = true;
                dtpNamGhi.Enabled = true;
                btnTimKiem4.Enabled = true;
            }
            else
            {
                HienChon1();
                AnNhap1();
                NhapMoi1();
                btnTimKiem4.Enabled = false;
            }
        }

        private void btnLoad4_Click(object sender, EventArgs e)
        {
            grwPTD2.DataSource = phieutd.PhieuTheoDoi_All_MaYTa(manv);
            CanChinh3(grwPTD2);
            txtTongSo3.Text = grwPTD2.RowCount.ToString();
            btnXoa4.Enabled = true;
        }

        private void txtTongSo3_TextChanged(object sender, EventArgs e)
        {
            if (txtTongSo3.Text != "")
                btnXoa4.Enabled = true;
            else
                btnXoa4.Enabled = false;
        }

        private void grwPTD2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = e.RowIndex;
            txtMaPhieu5.Text = grwPTD2.Rows[row].Cells[0].Value.ToString();
        }

        private void btnXoa4_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Bạn muốn xóa phiếu theo dõi có mã [" + txtMaPhieu5.Text + "]?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int kq = phieutd.PhieuTheoDoi_Xoa(Convert.ToInt32(txtMaPhieu5.Text)); ;
                    if (kq != 0)
                    {
                        MessageBox.Show("Xóa thành công !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        btnLoad4.PerformClick();
                        return;
                    }
                    else
                        MessageBox.Show("Xóa thất bại, bệnh nhân có phiêu theo dõi này chưa xuất viện !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            catch
            { }
        }

        private bool KiemTraNhap3()
        {
            bool kq = true;
            if (txtDienBien1.Text.Trim() == "")
            {
                if (txtDienBien1.Text.Trim() == "")
                    errorProvider1.SetError(txtDienBien1, "Bạn chưa nhập dữ liệu !");
                kq = false;
            }
            else
            {
                errorProvider1.Clear();
                kq = true;
            }
            return kq;
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                if (KiemTraNhap3())
                {
                    if (MessageBox.Show("Bạn có muốn cập nhật không ?", "???", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int kq = phieutd.PhieuTheoDoi_CapNhat(new PhieuTheoDoi_Info(txtMaPhieu1.Text, int.Parse(txtMaBA1.Text),
                            dtpNgayGhi1.Value, txtDienBien1.Text, manv, tennv));
                        if (kq > 0)
                        {
                            MessageBox.Show("Cập nhật thành công !", "Infomation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            grwPhieuTD.DataSource = phieutd.PhieuTheoDoi_TimTheoMaPhieu_MaYTa(manv,int.Parse(txtMaPhieu1.Text));
                            CanChinh3(grwPhieuTD);
                            return;
                        }
                        else
                            MessageBox.Show("Cập nhật thất bại !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                        return;
                }
                else
                    MessageBox.Show("Dữ liệu nhập không hợp lệ !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch { }
        }

        private void txtDienBien1_TextChanged(object sender, EventArgs e)
        {
            if (txtDienBien1.Text != "")
                errorProvider1.Clear();
            else
                errorProvider1.SetError(txtDienBien1, "Bạn chưa nhập dữ liệu !");
        }
    }
}
